<!-- NewPracticeAppraise_frame.html -->
<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/html-base.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/public.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/list.css"/>
    <script type="text/javascript" src="../../script/jquery.min.js"></script>
    <script type="text/javascript" src="../../script/newresize.js"></script>
    <script type="text/javascript" src="../../script/mui.min.js"></script>
    <style type="text/css">
    	body,html{overflow: hidden;}
    	.header{position: absolute;}
    	.container {
		    padding-top: 0;
		}
		.tag-div{
			/*border-top: 0.02rem solid #f3f5f7;*/
			font-size: 0.4rem;
		    line-height: 0.4rem;
		    position: relative;
		    overflow: hidden;
		}
		.sub-tag-div{
			width: 50%;
			float: left;
		}
		.sub-tag-box{
			padding: 0.3rem;
		}
		.sub-tag{
			padding: 0.2rem 0.3rem;
			border: 0.02rem solid #999;
			color: #999;
			border-radius: 0.4rem;
			overflow: hidden;
			position: relative;
		}
		.content-tag{
			overflow: hidden;
			text-overflow : ellipsis;
			white-space: nowrap;
			text-align: center;
		}
		.active-tag .sub-tag{
			border: 0.02rem solid #d65357;
			color: #d65357;
		}
		.fankuicont .fankui-txt {
		    height: 4.05rem;
		}
		.section-div{
			border-bottom: 0.04rem solid #f3f5f7;
			border-top: 0.04rem solid #f3f5f7;
			font-size: 0.3rem;
			line-height: 0.3rem;
			padding: 0.3rem;
			color: #999;
			float: left;
			width: 100%;
		}
		.score-div{
			display: inline;
			width: 50px;
			height: 18px;
			transform: rotate(50deg);
			position: absolute;
			top: -2px;
			right: -17px;
			background-color: #999;
		}
		.active-tag .score-div{
			background-color: #d65357;
		}
		.score-span{
			font-size: 12px;
			color: white;
			height: 14px;
			width: 50px;
			line-height: 14px;
			text-align: center;
			transform: scale(0.6);
			position: absolute;
			bottom: 0;
		}
		.section-content-div{
			border-bottom: 0.02rem solid #f3f5f7;
			position: relative;
			overflow: hidden;
		}
    </style>
</head>
<body>
	<div class="container fankuicontainer">
		<form>
			<div class="lungangcontainer">
				<div class="lungboxs">
					<div class="lung-titbox">徒弟</div>
					<div id="uname" class="lung-sf">--</div>
					<div id="tag_list" class="tag-div">

						<!-- <div class="section-div">
							KPI
						</div>
						<div class="sub-tag-div active-tag">
							<div class="sub-tag-box">
								<div class="sub-tag">
									<div class="content-tag">
										动手能力强动手能力强动手能力强动手能力强动手能力强
									</div>
									<div class="score-div">
										<span class="score-span">
											10.00
										</span>
									</div>
								</div>
							</div>
						</div>
						<div class="sub-tag-div">
							<div class="sub-tag-box">
								<div class="sub-tag">
									<div class="content-tag">
										动手能力强动手能力强动手能力强动手能力强动手能力强
									</div>
									<div class="score-div">
										<span class="score-span">
											10.00
										</span>
									</div>
								</div>
							</div>
						</div>
						<div class="sub-tag-div">
							<div class="sub-tag-box">
								<div class="sub-tag">
									<div class="content-tag">
										动手能力强动手能力强动手能力强动手能力强动手能力强
									</div>
									<div class="score-div">
										<span class="score-span">
											10.00
										</span>
									</div>
								</div>
							</div>
						</div> -->

					</div>
				</div>
				<div class="">
					<p class="tips-txt2">评语</p>
					<div class="fankuicont">
						<textarea id="comment" name="" rows="" cols="" placeholder="请输入内容" maxlength="500" class="fankui-txt"></textarea>
					</div>
					<div class="submitbtn" id="submitbtn"  onclick="onSubmitClick()">提交</div>
				</div>
			</div>
		</form>
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript" src="../../script/timeStampTool.js"></script>
<script type="text/javascript">
	var readyOnly = false;
	var selectedTagArr = new Array();
	var kpi_scores = 0;
	var ability_score = 0;
	var event_score = 0;
	apiready = function(){
		prepareData();
		// loadData();
		loadTagData();
	}
	function prepareData(){
		var uname = api.pageParam.rename1;
		$('#uname').text(uname);
	}
	function loadData(){
		var params = {
			sfid : $api.getStorage('cfnetppuid'),
			uid : api.pageParam.uid,
			jid : $api.getStorage('cfnetppjid')
		};
		cfnetppPOST(url_newPracticeComment, params, false, function(data, status){
			if (status == 'success') {
				if (data.code == 200) {
					var jsonData = data.data;
					if (jsonData == undefined || jsonData == null || jsonData == [] || jsonData == '') {//未评价
						loadTagData();
						$('#submitbtn').show();
					}else{//已评价
						readyOnly = true;
						document.getElementById('comment').readOnly = true;
						$('#submitbtn').hide();
						setupCurrentData(jsonData);
					}
				}
			}
		});
	}
	function setupCurrentData(dataArr){
		var lastData = dataArr[0];
		var content = lastData.content;
		$('#comment').val(content);
		var label_list = lastData.label_list;
		if (label_list.constructor == Array && label_list.length > 0) {
			for (var i = 0; i < label_list.length; i++) {
				var labelData = label_list[i];
				$('#tag_list').append(tagCellHtml(1, labelData));
			}
		}
	}
	function loadTagData(){
		var params = {
			uid : $api.getStorage('cfnetppuid'),
			jid : $api.getStorage('cfnetppjid')
		};
		api.showProgress({
		    style: 'default',
		    animationType: 'fade',
		    title: '数据加载中...',
		    text: '',
		    modal: false
		});
		cfnetppPOST(url_newPracticeScoreTagList, params, false, function(data, status){
			api.hideProgress();
			if (status == 'success') {
				if (data.code == 200) {
					var tagArr = data.data;
					if (tagArr != undefined && tagArr != null && tagArr.constructor == Array && tagArr.length > 0) {
						for (var i = 0; i < tagArr.length; i++) {
							var sectionData = tagArr[i];
							var label_list = sectionData.label_list;
							if (label_list.length > 0) {
								$('#tag_list').append(sectionHtml(0, sectionData));
							}
						}
						setupTagCellClick();
					}
				}
			}
		});
	}
	function sectionHtml(type, sectionData){
		var type_name = sectionData.type_name;
		var labelHtml = '<div class="section-div">'+
							type_name+
						'</div>';
		var label_list = sectionData.label_list;
		var type_id = sectionData.id;
		for (var i = 0; i < label_list.length; i++) {
			var label = label_list[i];
			label["type_id"] = type_id;
			labelHtml += tagCellHtml(type, label);
		}
		return labelHtml;
	}
	function setupTagCellClick(){
		$('.sub-tag-div').unbind('click');
		$('.sub-tag-div').click(function(){
			if (readyOnly == true) {
				return;
			}
			var id = $(this).attr('id');
			var type_id = $(this).attr('type_id');
			var score = $(this).attr('score');
			if ($(this).hasClass('active-tag')) {
				$(this).removeClass('active-tag');
				for (var i = 0; i < selectedTagArr.length; i++) {
					var tab_id = selectedTagArr[i];
					if (tab_id == id){
						selectedTagArr.splice(i, 1);
						if (type_id == 1) {//KPI
							kpi_scores -= parseInt(score);
						}else if(type_id == 2){//能力
							ability_score -= parseInt(score);
						}else if(type_id == 3){//事件
							event_score -= parseInt(score);
						}
					}
				}
			}else{
				$(this).addClass('active-tag');
				selectedTagArr.push(id);
				if (type_id == 1) {//KPI
					kpi_scores += parseInt(score);
				}else if(type_id == 2){//能力
					ability_score += parseInt(score);
				}else if(type_id == 3){//实践
					event_score += parseInt(score);
				}
			}
			// console.log(JSON.stringify(selectedTagArr));
		});
	}
	function tagCellHtml(status, data){
		var statusClass = '';
		if (status == 1) {
			statusClass = 'active-tag';
		}
		var score = data.score;
		var scoreHtml = '';
		if (score != undefined && score != null) {
			scoreHtml = '<div class="score-div">'+
							'<span class="score-span">'+
								score+
							'</span>'+
						'</div>';
		}
		return '<div id="'+data.label_id+'" type_id="'+data.type_id+'" score="'+score+'" class="sub-tag-div '+statusClass+'">'+
					'<div class="sub-tag-box">'+
						'<div class="sub-tag">'+
							'<div class="content-tag">'+
								data.label_name+
							'</div>'+
							scoreHtml+
						'</div>'+
					'</div>'+
				'</div>';
	}
	function isSpace(str){
		if (str == null || str == '' || str.replace(/(^\s*)|(\s*$)/g, "") == '') {
            return true;
        }
        return false;
	}
	function submitScore(){
		var params = {
			jid : $api.getStorage('cfnetppjid'),
			uid : api.pageParam.uid,
			gwid : api.pageParam.gwid,
			sxfpid : api.pageParam.id,
			kpi_scores : kpi_scores,
			ability : ability_score,
			event : event_score,
			sfid : $api.getStorage('cfnetppuid')
		};
		api.showProgress({
		    style: 'default',
		    animationType: 'fade',
		    title: '提交中...',
		    text: '',
		    modal: true
		});
		// console.log(JSON.stringify(params) + '\n' + url_putEnterpriseScore);
		cfnetppPOST(url_putEnterpriseScore, params, false, function(data, status) {
			api.hideProgress();
			if (status == 'success') {
				//1,成功，返回success
				if (data.code == 200) {
					api.toast({
					    msg: '提交成功'
					});
					api.sendEvent({
					    name: 'MasterGradeListNotifi'
					});
					setTimeout(function(){
						api.closeWin({
						    name: 'NewPracticeAppraise_win'
						});
					}, 1000);
					//2,您本月已提交过日报,返回has
				} else {
					api.toast({
					    msg: data.message
					});
				}
			} else {
				api.toast({
				    msg: '网络异常,请检查网络!'
				});
			}
		});
	}
	function onSubmitClick(applyStatus){
		submitScore();
		var content = $('#comment').val();
		// if (isSpace(content) == true) {
		// 	api.toast({
		// 	    msg: '请输入评语后再提交'
		// 	});
		// 	return;
		// }
		var params = {
			sfid : $api.getStorage('cfnetppuid'),
			uid : api.pageParam.uid,
			jid : $api.getStorage('cfnetppjid'),
			label_ids : selectedTagArr.join(','),
			content : content
		};
		
		// console.log(JSON.stringify(params)+'\n'+url_newPracticeScore);
		cfnetppPOST(url_newPracticeScore, params, false, function(data, status){
			return;//只做记录不作操作
			if (status == 'success') {
				if (data.code == 200) {
					// api.toast({
					//     msg: '提交成功'
					// });
					// setTimeout(function(){
					// 	api.closeWin({
					// 	    name: 'NewPracticeAppraise_win'
					// 	});
					// }, 1000);
				}else{
					// api.toast({
					//     msg: data.message
					// });
				}
			}else{
				// api.toast({
				//     msg: '网络异常'
				// });
			}
		});
	}
</script>
</html>